package com.chenfeng.service.impl;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.bjsxt.common.util.PageInfoUtil;
import com.chenfeng.dao.IUserDao;
import com.chenfeng.pojo.ARole;
import com.chenfeng.pojo.AUser;
import com.chenfeng.service.IUserservice;
@Service("service")
public class UserServiceImpl implements IUserservice
{
	@Resource
	IUserDao usedao;
	/**
	 * 插入一条数据
	 */
	public JSONObject insertUserService(AUser user)
	{	
		JSONObject result = new JSONObject();
		int a = this.usedao.insert(user);
		if(a>0)
		{
			result.put("code", "0");
			result.put("info", "插入成功");
		}else
		{
			result.put("code", "1");
			result.put("info", "插入失败");
		}
		return result;
	}

	@Override
	/***
	 * 
	 * 更新一条数据
	 */
	public JSONObject updateUserService(AUser user)
	{
		JSONObject result = new JSONObject();
		int a = this.usedao.update(user);
		System.out.println("a的值是"+a);
		if(a>0)
		{
			result.put("code", 0);
			result.put("info", "更新成功");
			JSONObject data = new JSONObject();
			data.put("updta数据", user);
			result.put("hello", data);
			
		}else
		{
			result.put("code", 1);
			result.put("info", "更新失败");
		}
		return result;
	}

	@Override
	/*
	 * 删除一条数据
	 */
	public JSONObject deleteUserService(Map<String, Object> map)
	{
		JSONObject result = new JSONObject();
		int a = this.usedao.delete(map);
		if(a<0)
		{
			result.put("code", 0);
			result.put("info", "删除失败");
		}else
		{
			result.put("code", 1);
			result.put("info", "删除成功");
		}
		return result;
	}
    /**
     * 
     * 查找一条数据
     */
	@Override
	public AUser findOneUserService(Map<String, Object> map)
	{
		
		return this.usedao.findOne(map);
	}

	@Override
	/**
	 * 查找多条数据
	 */
	public List<AUser> findListCondUserService(PageInfoUtil pageInfoUtil, Map<String, Object> map)
	{
		//创建一个集合给她一个空集合
		List<AUser> list =  java.util.Collections.EMPTY_LIST;
		//当keyword有值得时候添加%%
		if(map.get("keyword")!=null)
		{
			map.put("keyword", "%"+map.get("keyword")+"%");
		}
		//当pageinfoutil不等于空的时候用的是分页查询
		if(pageInfoUtil != null)
		{  //先查询总记录数
			map.put("pageCount", "true");
			map.put("currRecord", pageInfoUtil.getCurrRecord());
			map.put("pageSize", pageInfoUtil.getPageSize());
			list = usedao.findCondList(map);
			pageInfoUtil.setTotalRecord(list.get(0).getId());
			//查询分页
			map.put("pageCount", "false");
			list = usedao.findCondList(map);
		}else
		{   //查询不分页
			list = this.usedao.findCondList(map);
		}
		return list;
	}

	@Override
	public JSONObject insertroleService(ARole role)
	{
		
		return null;
	}

	@Override
	public JSONObject updateroleService(ARole role)
	{
		
		return null;
	}

	@Override
	public JSONObject deleteroleService(Map<String, Object> map)
	{
		
		return null;
	}

	@Override
	public ARole findOneroleService(Map<String, Object> map)
	{
		
		return null;
	}

	@Override
	public List<ARole> findListCondroleService(PageInfoUtil pageInfoUtil, Map<String, Object> map)
	{
		
		return null;
	}
	
}
